<template>
  <view class="content">
    <!-- 认证服务 -->
    <view class="nav" style="width: 100%">
      <view
        v-for="(item, index) in category"
        @click="SwitchVariety(item, index)"
        :key="index"
        :class="{ active: activeIndex === index }"
        >{{ item }}</view
      >
    </view>
    <!-- 用户 -->
    <view class="cont" v-if="activeIndex == 0">
      <!-- <uni-steps :options="list1" active-icon="checkbox" :active="active" /> -->
      <view class="item" v-if="activeName == 0">
        <uni-section title="实名信息" type="line">
          <view class="example">
            <!-- 基础用法，不包含校验规则 -->
            <uni-forms
              ref="form4"
              :modelValue="enterprise_info"
              label-width="140px"
              label-position="top"
            >
              <uni-forms-item required name="Legal_Person">
                <view class="">
                  <!-- <view @click="select1" class="font">
                    <view
                      style="border: 1px solid #f5f5f5; width: 80px; height: 80px; border-radius 20rpx; display: flex; justify-content: center; align-items: center;"
                      class="mb-2"
                    >
                      <image
                        :src="Domain_ICON + '/sc.png'"
                        mode="scaleToFill"
                        style="width: 70px; height: 70px"
                      />
                    </view>
                    请上传土地资格证
                  </view> -->
                  <view>
                    <!-- <view v-if="imgUrl">
                      <image
                          :src="imgUrl"
                          mode="scaleToFill"
                          style="width: 70px; height: 70px"
                        />
                    </view> -->
                    <view @click="select1(1)" class="font">
                      <view
                        style="border: 1px solid #f5f5f5; width: 80px; height: 80px; border-radius 20rpx; display: flex; justify-content: center; align-items: center;"
                        class="mb-2"
                      >
                        <image
                          :src="Domain_ICON + '/sc.png'"
                          mode="scaleToFill"
                          style="width: 70px; height: 70px"
                        />
                      </view>
                      请上传身份证正面
                    </view>
                  </view>
                  <view @click="select1(0)" class="font">
                    <!-- <view v-if="imgUrl2">
                      <image
                          :src="imgUrl2"
                          mode="scaleToFill"
                          style="width: 70px; height: 70px"
                        />
                    </view> v-else -->
                    <view
                      style="border: 1px solid #f5f5f5; width: 80px; height: 80px; border-radius 20rpx; display: flex; justify-content: center; align-items: center;"
                      class="mb-2"
                    >
                      <image
                        :src="Domain_ICON + '/sc.png'"
                        mode="scaleToFill"
                        style="width: 70px; height: 70px"
                      />
                    </view>
                    请上传身份证反面
                  </view>
                </view>
              </uni-forms-item>

              <uni-forms-item label="姓名" required name="Legal_Person">
                <uni-easyinput
                  v-model="
                    enterprise_info.Children.enterprise_legal_person[0]
                      .Legal_Person
                  "
                  placeholder="请输入姓名"
                />
              </uni-forms-item>

              <uni-forms-item label="证件类型" required name="IDType">
                <uni-data-select
                  v-model="
                    enterprise_info.Children.enterprise_legal_person[0].IDType
                  "
                  :localdata="range"
                ></uni-data-select>
              </uni-forms-item>

              <uni-forms-item label="证据号码" required name="ID_Number">
                <uni-easyinput
                  v-model="
                    enterprise_info.Children.enterprise_legal_person[0]
                      .ID_Number
                  "
                  placeholder="请输入证据号码"
                />
              </uni-forms-item>
            </uni-forms>
            <view class="foot">
              <button
                type="primary"
                size="mini"
                style="margin: 30px 10px; width: 100px"
                @click="previous"
              >
                上一步
              </button>
              <button
                type="primary"
                size="mini"
                style="margin: 30px 10px; width: 100px"
                @click="submitForm1('form4')"
              >
                下一步
              </button>
            </view>
          </view>
        </uni-section>
      </view>
      <view class="item" v-if="activeName == 1">
        <uni-section title="银行账户信息" type="line">
          <view class="example">
            <uni-forms
              ref="form5"
              :modelValue="enterprise_info"
              label-width="140px"
              label-position="top"
            >
              <uni-forms-item label="开户名" required name="Account_Name">
                <uni-easyinput
                  v-model="
                    enterprise_info.Children.enterprise_account[0].Account_Name
                  "
                  placeholder="请输入开户名"
                />
              </uni-forms-item>
              <uni-forms-item label="开户行" required>
                <uni-data-select
                  v-model="
                    enterprise_info.Children.enterprise_account[0].Bank_Name
                  "
                  :localdata="range"
                  @change="change"
                ></uni-data-select>
              </uni-forms-item>
              <uni-forms-item label="银行账号" required name="Account_Number">
                <uni-easyinput
                  v-model="
                    enterprise_info.Children.enterprise_account[0]
                      .Account_Number
                  "
                  placeholder="请输入银行账号"
                />
              </uni-forms-item>
            </uni-forms>
            <view class="foot">
              <button
                type="primary"
                size="mini"
                style="margin: 30px 10px; width: 100px"
                @click="previousPage(1)"
              >
                上一步
              </button>
              <button
                type="primary"
                size="mini"
                style="margin: 30px 10px; width: 100px"
                @click="nextPage1('form5')"
              >
                下一步
              </button>
            </view>
          </view>
        </uni-section>
      </view>
      <view class="item" v-if="activeName == 2">
        <uni-section title="联系方式" type="line">
          <view class="example">
            <!-- 基础用法，不包含校验规则 -->
            <uni-forms
              ref="form6"
              :modelValue="enterprise_info"
              label-width="140px"
              label-position="top"
            >
              <uni-forms-item label="地址" required name="address">
                <uni-easyinput v-model="address" placeholder="请输入地址" />
              </uni-forms-item>
              <uni-forms-item
                label="详细地址"
                required
                name="Enterprise_Address"
              >
                <uni-easyinput
                  v-model="enterprise_info.Enterprise_Address"
                  placeholder="请输入详细地址"
                />
              </uni-forms-item>
              <uni-forms-item label="邮箱" required name="E_Mail">
                <uni-easyinput
                  v-model="enterprise_info.E_Mail"
                  placeholder="请输入邮箱"
                />
              </uni-forms-item>
              <uni-forms-item label="手机号" required name="Mobile">
                <uni-easyinput
                  v-model="
                    enterprise_info.Children.enterprise_legal_person[0].Mobile
                  "
                  placeholder="请输入手机号"
                />
              </uni-forms-item>
              <uni-forms-item label="验证码" required name="Code">
                <view class="flex align-center">
                  <uni-easyinput
                    v-model="
                      enterprise_info.Children.enterprise_legal_person[0].Code
                    "
                    placeholder="请输入手机短信验证码"
                  />
                  <button
                    size="mini"
                    type="primary"
                    class="uni-button"
                    v-if="time"
                    @click="sendMessage()"
                  >
                    获取验证码
                  </button>
                  <button v-else type="warn" class="uni-button">
                    {{ secend }}
                  </button>
                </view>
              </uni-forms-item>
            </uni-forms>
            <view class="foot">
              <button
                :loading="loading"
                type="primary"
                size="mini"
                style="margin: 30px 10px; width: 100px"
                @click="previousPage(2)"
              >
                上一步
              </button>
              <button
                :loading="loading"
                type="primary"
                size="mini"
                style="margin: 30px 10px; width: 100px"
                @click="submitForm3('form6')"
              >
                提交
              </button>
            </view>
          </view>
        </uni-section>
      </view>
    </view>
    <!-- 企业 -->
    <view class="cont" v-if="activeIndex == 1">
      <!-- <uni-steps :options="list1" active-icon="checkbox" :active="active" /> -->
      <view class="item" v-if="activeName == 0">
        <uni-section title="企业信息" type="line">
          <view class="example">
            <!-- 基础用法，不包含校验规则 -->
            <uni-forms
              ref="form1"
              :modelValue="enterprise_info"
              label-width="140px"
              label-position="top"
            >
              <!-- <uni-file-picker
                @select="select"
                limit="1"
                title="请上传营业执照"
              ></uni-file-picker> -->
              <view @click="select" class="font">
                    <view
                      style="border: 1px solid #f5f5f5; width: 80px; height: 80px; border-radius 20rpx; display: flex; justify-content: center; align-items: center;"
                      class="mb-2"
                    >
                      <image
                        :src="Domain_ICON + '/sc.png'"
                        mode="scaleToFill"
                        style="width: 70px; height: 70px"
                      />
                    </view>
                    请上传营业执照
                  </view>
              <uni-forms-item label="企业全称" required name="Enterprise_Name">
                <uni-easyinput
                  @blur="blur"
                  v-model="enterprise_info.Enterprise_Name"
                  placeholder="请输入姓名"
                />
              </uni-forms-item>
              <uni-forms-item
                label="统一社会信用代码"
                required
                name="Tax_Number"
              >
                <uni-easyinput
                  v-model="enterprise_info.Tax_Number"
                  placeholder="请输入证据号码"
                />
              </uni-forms-item>
              <uni-forms-item label="企业地址" required name="address">
                <uni-easyinput v-model="address" placeholder="请输入证据号码" />
              </uni-forms-item>
              <uni-forms-item
                label="公司详细地址"
                required
                name="Enterprise_Address"
              >
                <uni-easyinput
                  v-model="enterprise_info.Enterprise_Address"
                  placeholder="请输入证据号码"
                />
              </uni-forms-item>
            </uni-forms>
            <view class="foot">
              <button
                type="primary"
                size="mini"
                style="margin: 30px 10px; width: 100px"
                @click="previous"
              >
                上一步
              </button>
              <button
                type="primary"
                size="mini"
                style="margin: 30px 10px; width: 100px"
                @click="submitForm('form1')"
              >
                下一步
              </button>
            </view>
          </view>
        </uni-section>
      </view>
      <view class="item" v-if="activeName == 1">
        <uni-section title="银行账户信息" type="line">
          <view class="example">
            <uni-forms
              ref="form2"
              :modelValue="enterprise_info"
              label-width="140px"
              label-position="top"
            >
              <uni-forms-item label="开户名" required name="Account_Name">
                <uni-easyinput
                  v-model="
                    enterprise_info.Children.enterprise_account[0].Account_Name
                  "
                  placeholder="请输入开户名"
                />
              </uni-forms-item>
              <uni-forms-item label="开户行" required>
                <uni-data-select
                  v-model="
                    enterprise_info.Children.enterprise_account[0].Bank_Name
                  "
                  :localdata="Banks"
                  @change="change"
                ></uni-data-select>
              </uni-forms-item>
              <uni-forms-item label="银行账号" required name="Account_Number">
                <uni-easyinput
                  v-model="
                    enterprise_info.Children.enterprise_account[0]
                      .Account_Number
                  "
                  placeholder="请输入银行账号"
                />
              </uni-forms-item>
            </uni-forms>
            <view class="foot">
              <button
                type="primary"
                size="mini"
                style="margin: 30px 10px; width: 100px"
                @click="previousPage(1)"
              >
                上一步
              </button>
              <button
                type="primary"
                size="mini"
                style="margin: 30px 10px; width: 100px"
                @click="nextPage('form2')"
              >
                下一步
              </button>
            </view>
          </view>
        </uni-section>
      </view>
      <view class="item" v-if="activeName == 2">
        <uni-section title="联系方式" type="line">
          <view class="example">
            <!-- 基础用法，不包含校验规则 -->
            <uni-forms
              ref="form3"
              :modelValue="enterprise_info"
              label-width="140px"
              label-position="top"
            >
              <uni-forms-item label="管理员姓名" required name="Legal_Person">
                <uni-easyinput
                  v-model="
                    enterprise_info.Children.enterprise_legal_person[0]
                      .Legal_Person
                  "
                  placeholder="请输入管理员姓名"
                />
              </uni-forms-item>
              <uni-forms-item label="管理员手机号" required name="Mobile">
                <uni-easyinput
                  v-model="
                    enterprise_info.Children.enterprise_legal_person[0].Mobile
                  "
                  placeholder="请输入管理员手机号"
                />
              </uni-forms-item>
              <uni-forms-item label="手机短信验证码" required name="Code">
                <view class="flex align-center">
                  <uni-easyinput
                    v-model="
                      enterprise_info.Children.enterprise_legal_person[0].Code
                    "
                    placeholder="请输入手机短信验证码"
                  />
                  <button
                    size="mini"
                    type="primary"
                    class="uni-button"
                    v-if="time"
                    @click="sendMessage()"
                  >
                    获取验证码
                  </button>
                  <button type="warn" v-else class="uni-button">
                    {{ secend }}
                  </button>
                </view>
              </uni-forms-item>
              <uni-forms-item label="管理员证件类型" required name="IDType">
                <uni-data-select
                  v-model="
                    enterprise_info.Children.enterprise_legal_person[0].IDType
                  "
                  :localdata="range"
                  @change="change"
                ></uni-data-select>
              </uni-forms-item>
              <uni-file-picker
                @select="select1"
                limit="2"
                title="请上传身份证正反面"
              ></uni-file-picker>
              <uni-forms-item label="管理员证件号码" required name="ID_Number">
                <uni-easyinput
                  v-model="
                    enterprise_info.Children.enterprise_legal_person[0]
                      .ID_Number
                  "
                  placeholder="请输入管理员证件号码"
                />
              </uni-forms-item>
            </uni-forms>
            <view class="foot">
              <button
                :loading="loading"
                type="primary"
                size="mini"
                style="margin: 30px 10px; width: 100px"
                @click="previousPage(2)"
              >
                上一步
              </button>
              <button
                :loading="loading"
                type="primary"
                size="mini"
                style="margin: 30px 10px; width: 100px"
                @click="submitForm2('form3')"
              >
                提交
              </button>
            </view>
          </view>
        </uni-section>
      </view>
    </view>
    <uni-popup ref="message" type="message">
      <uni-popup-message
        :type="msgType"
        :message="messageText"
        :duration="2000"
      ></uni-popup-message>
    </uni-popup>
  </view>
</template>
<script>
const app = getApp();
import { pathToBase64, base64ToPath } from "@/static/js/Base64.js";
import {
  BusinessPIC,
  getAddAction,
  getEditAction,
  CheckRegisterAction,
  GoodsInquiryKeyOriginal,
  getInquiryIDOriginal,
  parseIDCardAction,
} from "@/api/global.js";
export default {
  data() {
    return {
      Phone: "",
      code: "",
      screenWidth: uni.getSystemInfoSync().windowWidth,
      screenHigth: uni.getSystemInfoSync().windowHeight,
      ThemeColors: app.globalData.ThemeColors,
      Domain_ICON: app.globalData.Domain_ICON,
      isActive: false,
      type_index: null,
      active: 0,
      active1: 0,
      show: false,
      activeName: 0,
      activeIndex: 1,
      loading: false,
      address: "",
      formData1: {},
      timer: null,
      time: true,
      secend: 60,
      RandomCode: "",
      bank: [],
      Banks: [
        {
          value: "中国建设银行",
          text: "中国建设银行",
        },
        {
          id: 2,
          value: "中国工商银行",
          text: "中国工商银行",
        },
        {
          id: 3,
          value: "中国农业银行",
          text: "中国农业银行",
        },
        {
          id: 4,
          value: "中国银行",
          text: "中国银行",
        },
        {
          id: 5,
          value: "交通银行",
          text: "交通银行",
        },
        {
          id: 6,
          value: "中国邮政储蓄银行",
          text: "中国邮政储蓄银行",
        },
        {
          id: 7,
          value: "招商银行",
          text: "招商银行",
        },
        {
          id: 8,
          value: "中国民生银行",
          text: "中国民生银行",
        },
        {
          id: 9,
          value: "浦发银行",
          text: "浦发银行",
        },
        {
          id: 10,
          value: "中信银行",
          text: "中信银行",
        },
        {
          id: 11,
          value: "中国光大银行",
          text: "中国光大银行",
        },
        {
          id: 12,
          value: "华夏银行",
          text: "华夏银行",
        },
        {
          id: 13,
          value: "广发银行",
          text: "广发银行",
        },
        {
          id: 14,
          value: "兴业银行",
          text: "兴业银行",
        },
        {
          id: 15,
          value: "平安银行",
          text: "平安银行",
        },
        {
          id: 16,
          value: "恒丰银行",
          text: "恒丰银行",
        },
      ],
      enterprise_info: {
        //提交的表单
        Enterprise_Info_SerialNumber: "", //主键
        Enterprise_Name: "", //企业名称
        Industry_SubCategory_SerialNumber: "101000000000001",
        Industry_Category_SerialNumber: "100000000000001",
        Enterprise_Address: "", //企业注册地址
        Postal_Code: "", //邮政编号
        Tax_Number: "", //营业执照注册号
        Enterprise_Phone: "", //企业电话
        Enterprise_Contacts: "", //企业联系人
        Enterprise_Contacts_Mobile: "", //企业手机号
        Enterprise_Type: 1,
        Row_Status: 1,
        Picture_URL: "",
        E_Mail: "", //电子邮箱
        Children: {
          enterprise_legal_person: [
            {
              Enterprise_Legal_Person_SerialNumber: "",
              Enterprise_Info_SerialNumoer: "",
              Legal_Person: "", //法人姓名
              ID_Number: "", //法人身份证号
              Mobile: "", //法人手机号
              IDType: "", //证件类型
              ParseIDCard_Front: "", //身份证正面
              ParseIDCard_Back: "", //身份证背面
              Code: "", //手机号验证码
            },
          ],
          enterprise_account: [
            {
              Enterprise_Account_SerialNumber: "",
              Enterprise_Info_SerialNumoer: "",
              Bank_Name: "", //开户行
              Account_Name: "", //开户名
              Account_Number: "", //银行账号
            },
          ],
        },
      },
      user_info: {},
      rules1: {
        // 企业姓名
        Enterprise_Name: {
          rules: [
            {
              required: true,
              errorMessage: "请输入公司名称",
            },
            {
              min: 2,
              max: 50,
              errorMessage: "密码长度应在 6 到 10 个字符",
            },
          ],
        },
        Tax_Number: {
          rules: [
            {
              required: true,
              errorMessage: "请输入营业执照号",
            },
          ],
        },
        Picture_URL: {
          rules: [
            {
              required: true,
              errorMessage: "请上传企业营业执照",
              trigger: "change",
            },
          ],
        },
        Enterprise_Address: {
          rules: [
            {
              required: true,
              errorMessage: "请输入企业详细地址",
              trigger: "blur",
            },
          ],
        },
        E_Mail: {
          rules: [
            {
              required: true,
              errorMessage: "请输入电子邮箱",
              trigger: "blur",
            },
          ],
        },
        Mobile: {
          rules: [
            {
              required: true,
              errorMessage: "请输入手机号",
              trigger: "blur",
            },
            {
              pattern: /^1[3456789]\d{9}$/,
              errorMessage: "手机号码格式不正确",
              trigger: "blur",
            },
          ],
        },
      },
      rules2: {
        //银行开户名
        Account_Name: {
          rules: [
            {
              required: true,
              errorMessage: "请输入银行开户名",
              trigger: "blur",
            },
          ],
        },
        Bank_Name: {
          rules: [
            {
              required: true,
              errorMessage: "请选择开户行",
              trigger: "change",
            },
          ],
        },
        Account_Number: {
          rules: [
            {
              required: true,
              errorMessage: "请输入银行账号",
              trigger: "blur",
            },
          ],
        },
      },
      rules3: {
        //管理员姓名
        Legal_Person: {
          rules: [
            {
              required: true,
              errorMessage: "请输入管理员姓名",
              trigger: "blur",
            },
          ],
        },
        ID_Number: {
          rules: [
            {
              required: true,
              errorMessage: "请输入管理员证件号",
              trigger: "blur",
            },
          ],
        },
        Mobile: {
          rules: [
            {
              required: true,
              errorMessage: "请输入管理员手机号",
              trigger: "blur",
            },
            {
              pattern: /^1[3456789]\d{9}$/,
              errorMessage: "手机号码格式不正确",
              trigger: "blur",
            },
          ],
        },
        IDType: {
          rules: [
            {
              required: true,
              errorMessage: "请选择管理员证件类型",
              trigger: "change",
            },
          ],
        },
        Code: {
          rules: [
            {
              required: true,
              errorMessage: "请输入手机号验证码",
              trigger: "blur",
            },
            {
              min: 6,
              errorMessage: "短信验证码为6位有效数字",
              trigger: "blur",
            },
          ],
        },
      },
      msgType: "success",
      messageText: "这是一条成功提示",
      category: ["个人认证", "企业认证"],
      list1: [
        {
          title: "选择认证方式",
        },
        {
          title: "填写认证信息",
        },
        {
          title: "成功",
        },
      ],
      range: [
        {
          value: "0",
          text: "身份证",
        },
        {
          value: "1",
          text: "香港居民往来内地通行证",
        },
        {
          value: "2",
          text: "澳门居民往来内地通行证",
        },
        {
          value: "3",
          text: "护照",
        },
      ],
      activeIndex: 0,
      imgUrl:"" , //临时路径
      imgUlr:"" , //临时路径2
    };
  },
  onLoad() {
    this.enterprise_info.Children.enterprise_legal_person[0].Mobile =
      uni.getStorageSync("use");
  },
  methods: {
    async SwitchVariety(i, index) {
      this.activeIndex = index;
    },
    handleTabs(url) {
      uni.navigateTo({
        url,
      });
    },
    handleClick(tab, event) {
      console.log(tab.index);
    },
    blur() {
      this.CheckEnterprise(this.enterprise_info.Enterprise_Name);
    },
    type_method(index) {
      this.activeIndex = index;
    },
    async uploadImg(Data, FileName) {
      uni.showLoading({
        title: "图片解析中",
      });
      let data = {
        Data,
        FileName,
      };
      const res = await BusinessPIC({
        data,
      });
      uni.hideLoading();
      if (res.redirect && res.redirect == "REDIRECT") {
        uni.navigateTo({
          url: "/pages/My/Login",
        });
      } else if (res.Status == "success") {
        console.log(res);
        this.enterprise_info.Enterprise_Name = res.Data.Enterprise_Name;
        this.CheckEnterprise(this.enterprise_info.Enterprise_Name);
        this.enterprise_info.Tax_Number = res.Data.Tax_Number;
        this.enterprise_info.Picture_URL = res.Picture_URL;
        this.enterprise_info.Children.enterprise_legal_person[0].Legal_Person =
          res.Data.Legal_Person;
      }
    },
    //身份证
    async uploadImg1(Data, FileName) {
      uni.showLoading({
        title: "图片解析中",
      });
      let data = {
        Data,
      };
      const res = await parseIDCardAction({
        data,
      });
      uni.hideLoading();
      if (res.redirect && res.redirect == "REDIRECT") {
        uni.navigateTo({
          url: "/pages/My/Login",
        });
      } else if (res.Status == "success") {
        console.log(res);
        if (res.ID_Number) {
          this.enterprise_info.Children.enterprise_legal_person[0].IDType = "0";
          this.enterprise_info.Children.enterprise_legal_person[0].ID_Number =
            res.ID_Number;
          this.enterprise_info.Children.enterprise_legal_person[0].Legal_Person =
            res.name;
          this.enterprise_info.Enterprise_Address = res.address;
          this.enterprise_info.Children.enterprise_legal_person[0].ParseIDCard_Front =
            Data;
        } else {
          const expirationDate = res.validity_enddate;
          // 获取当前日期
          const currentDate = new Date();

          // 将身份证上的有效期转换为 Date 对象
          const expirationDateObj = new Date(expirationDate);

          // 比较当前日期与身份证有效期
          if (currentDate > expirationDateObj) {
              uni.showToast({
                title: "身份证已过期,请重新上传",
                icon: "none",
              });
            return
          }
          this.enterprise_info.Children.enterprise_legal_person[0].ParseIDCard_Back =
            Data;
        }
      }
    },
    change(e) {
      console.log(e);
    },
    async CheckEnterprise(Enterprise_Name) {
      const res = await CheckRegisterAction({
        data: {
          Enterprise_Name,
        },
      });
      console.log(res);
      if (res.redirect && res.redirect == "REDIRECT") {
        uni.showToast({
          title: "登录超时,请重新登录",
          icon: "none",
        });
        setTimeout(function () {
          uni.navigateTo({
            url: "/pages/My/Login",
          });
        }, 2000);
      } else if (res.Status == "success") {
        this.show = false;
      } else {
        this.show = true;
      }
    },
    nextPage(formName) {
      this.$refs[formName]
        .validate()
        .then((res) => {
          this.enterprise_info.Enterprise_Address =
            this.address[0] +
            this.address[1] +
            this.address[2] +
            this.enterprise_info.Enterprise_Address;
          this.activeName = 2;
        })
        .catch((err) => {
          uni.showToast({
            title: "请检查页面表单是否填写正确或有未填写项",
            icon: "none",
          });
          console.log("表单错误信息：", err);
        });
    },
    nextPage1(formName) {
      this.$refs[formName]
        .validate()
        .then((res) => {
          this.activeName = 2;
        })
        .catch((err) => {
          uni.showToast({
            title: "请检查页面表单是否填写正确或有未填写项",
            icon: "none",
          });
          console.log("表单错误信息：", err);
        });
    },
    next() {
      this.type_index = this.activeIndex;
      this.active = 1;
      this.active1 = 1;
    },
    previousPage(i) {
      if (i == 2) {
        this.activeName = 2;
      } else {
        this.activeName = 1;
      }
    },
    previous() {
      this.activeName = 0;
    },
    submitForm(formName) {
      this.$refs[formName]
        .validate()
        .then((res) => {
          if (this.enterprise_info.Picture_URL == "") {
            uni.showToast({
              title: "请上传企业营业执照",
              icon: "none",
            });
            return;
          }
          if (this.show) {
            uni.showToast({
              title: "您要认证的企业已被认证",
              icon: "none",
            });
            return;
          }
          this.enterprise_info.Enterprise_Address =
            this.address[0] +
            this.address[1] +
            this.address[2] +
            this.enterprise_info.Enterprise_Address;
          this.activeName = 1;
        })
        .catch((err) => {
          uni.showToast({
            title: "请检查页面表单是否填写正确或有未填写项",
            icon: "none",
          });
          console.log("表单错误信息：", err);
        });
    },
    submitForm1(formName) {
      this.$refs[formName]
        .validate()
        .then((res) => {
          // if (this.enterprise_info.Picture_URL == "") {
          //   uni.showToast({
          //     title: "请上传土地资格证",
          //     icon: "none",
          //   });
          //   return;
          // }
          if (
            this.enterprise_info.Children.enterprise_legal_person[0]
              .ParseIDCard_Front == ""
          ) {
            uni.showToast({
              title: "请上传身份证正面",
              icon: "none",
            });
            return;
          }
          if (
            this.enterprise_info.Children.enterprise_legal_person[0]
              .ParseIDCard_Back == ""
          ) {
            uni.showToast({
              title: "请上传身份证背面",
              icon: "none",
            });
            return;
          }
          this.activeName = 1;
        })
        .catch((err) => {
          uni.showToast({
            title: "请检查页面表单是否填写正确或有未填写项",
            icon: "none",
          });
          console.log("表单错误信息：", err);
        });
    },
    sendMessage(i) {
      if (
        this.enterprise_info.Children.enterprise_legal_person[0].Mobile == ""
      ) {
        uni.showToast({
          title: "请先输入正确的手机号再点击发送",
          icon: "none",
        });
        return;
      }
      const reg = /^1[3-9]\d{9}$/;
      if (
        !reg.test(
          this.enterprise_info.Children.enterprise_legal_person[0].Mobile
        )
      ) {
        uni.showToast({
          title: "请检查手机号格式是否正确",
          icon: "none",
        });
        return;
      }
      this.time = false;
      this.secend = 60;
      this.secend--;
      this.timer = setInterval(() => {
        if (this.secend == "01") {
          clearInterval(this.timer);
          this.time = true;
          return;
        }
        this.secend--;
        if (this.secend < 10) {
          this.secend = "0" + this.secend;
        }
      }, 1000);
      let code = "";
      for (let i = 0; i < 6; i++) {
        code += parseInt(Math.random() * 10);
      }
      this.RandomCode = code;
      uniCloud
        .callFunction({
          name: "sendSms", //对应的云函数名
          data: {
            phone:
              this.enterprise_info.Children.enterprise_legal_person[0].Mobile,
            data: {
              name: "众菌联",
              code: this.RandomCode, //随机生成的验证码，如123456
              action: "注册", //校验类型为“注册”
              expMinute: "5", //短信的有效期，5分钟
            },
          },
        })
        .then((res) => {
          if (res.success) {
            uni.showToast({
              title: "短信已发送",
              icon: "none",
            });
          }
        })
        .catch((msg) => {
          console.log(msg);
          uni.showToast({
            title: "系统错误!请稍后重试",
            icon: "none",
          });
        });
    },

    select() {
      const _this = this;
      uni.chooseImage({
        count: 1, //默认9
        sizeType: ["original", "compressed"], //可以指定是原图还是压缩图，默认二者都有
        sourceType: ["album","camera"], //从相册选择
        success: function (e) {
          console.log(e);
          if (e.tempFiles[0].size > 2000000) {
            uni.showToast({
              title: "上传图片过大",
              icon: "none",
            });
            return;
          }
          if (e.tempFiles[0].size < 5000) {
            uni.showToast({
              title: "上传图片过小",
              icon: "none",
            });
            return;
          }
          pathToBase64(e.tempFilePaths[0])
            .then((path) => {
              _this.uploadImg(path, e.tempFilePaths[0]);
            })
            .catch((error) => {
              console.error(error);
            });
        },
      });
    },
    //身份证
    select1(i) {
      const _this = this;
      uni.chooseImage({
        count: 1, //默认9
        sizeType: ["original", "compressed"], //可以指定是原图还是压缩图，默认二者都有
        sourceType: ["album", "camera"], //从相册选择
        success: function (e) {
          console.log(e);
          if (i == "1") {
            _this.imgUlr = e.tempFilePaths[0]
          } else {
            _this.imgUlr = e.tempFilePaths[0]
          }
          this.imgUrl = e.tempFilePaths[0];
          if (e.tempFiles[0].size > 2000000) {
            uni.showToast({
              title: "上传图片过大",
              icon: "none",
            });
            return;
          }
          if (e.tempFiles[0].size < 5000) {
            uni.showToast({
              title: "上传图片过小",
              icon: "none",
            });
            return;
          }
          pathToBase64(e.tempFilePaths[0])
            .then((path) => {
              _this.uploadImg1(path, e.tempFiles[0].name);
            })
            .catch((error) => {
              console.error(error);
            });
        },
      });
    },
    // select1(e) {
    //
    // },
    submitForm2(formName) {
      this.enterprise_info.Children.enterprise_account[0].Bank_Name =
        this.bank[0];
      if (this.RandomCode == "") {
        uni.showToast({
          title: "请先点击发送获取验证码",
          icon: "none",
        });
        return;
      }
      // if (this.RandomCode != this.enterprise_info.Children.enterprise_legal_person[0].Code) {
      // 	uni.showToast({
      // 		title: '您输入的短信验证码有误!',
      // 		icon: 'none'
      // 	})
      // 	return
      // }
      if (
        this.enterprise_info.Children.enterprise_legal_person[0].IDType == "1"
      ) {
        if (
          this.enterprise_info.Children.enterprise_legal_person[0]
            .ParseIDCard_Front == "" ||
          this.enterprise_info.Children.enterprise_legal_person[0]
            .ParseIDCard_Back == ""
        ) {
          return;
        }
      }
      this.$refs[formName]
        .validate()
        .then((res) => {
          let data = {
            Primary_Key_Name: "User_Number", //主键名
            Primary_Key: uni.getStorageSync("use"),
            Data: "system_user_info",
            isNullEnterprise: true,
          };
          this.getOriginal(data, 1);
        })
        .catch((err) => {
          uni.showToast({
            title: "请检查页面表单是否填写正确或有未填写项",
            icon: "none",
          });
          console.log("表单错误信息：", err);
        });
    },
    submitForm3(formName) {
      this.enterprise_info.Children.enterprise_account[0].Bank_Name =
        this.bank[0];
      if (this.enterprise_info.E_Mail == "") {
        uni.showToast({
          title: "请输入邮箱",
          icon: "none",
        });
        return;
      }
      if (this.RandomCode == "") {
        uni.showToast({
          title: "请先点击发送获取验证码",
          icon: "none",
        });
        return;
      }
      console.log(
        this.RandomCode,
        this.enterprise_info.Children.enterprise_legal_person[0].Code
      );
      // if (this.RandomCode != this.enterprise_info.Children.enterprise_legal_person[0].Code) {
      // 	uni.showToast({
      // 		title: '您输入的短信验证码有误!',
      // 		icon: 'none'
      // 	})
      // 	return
      // }
      this.$refs[formName]
        .validate()
        .then((res) => {
          let data = {
            Primary_Key_Name: "User_Number", //主键名
            Primary_Key: uni.getStorageSync("use"),
            Data: "system_user_info",
            isNullEnterprise: true,
          };
          this.getOriginal(data, 0);
        })
        .catch((err) => {
          uni.showToast({
            title: "请检查页面表单是否填写正确或有未填写项",
            icon: "none",
          });
          console.log("表单错误信息：", err);
        });
    },
    async getOriginal(data, i) {
      uni.showLoading({
        title: "提交中...",
      });
      if (!this.loading) {
        this.loading = true;
        const res = await getInquiryIDOriginal({
          data,
        });
        if (res.redirect && res.redirect == "REDIRECT") {
          uni.navigateTo({
            url: "/pages/My/Login",
          });
        }
        this.user_info = res[0];
        let Data = {
          Data: JSON.stringify({
            enterprise_info: [this.enterprise_info],
          }),
        };
        this.getAdd(Data, i);
      }
    },

    async getAdd(data, i) {
      const res = await getAddAction({
        data,
      });
      this.loading = false;
      if (res.redirect && res.redirect == "REDIRECT") {
        uni.navigateTo({
          url: "/pages/My/Login",
        });
      } else if (res.Status == "success") {
        this.user_info.Authentication_Type = i;
        this.user_info.Admin_Type = 1;
        this.user_info.Enterprise_Info_SerialNumber = res.Data;
        let Data = {
          Data: JSON.stringify({
            Modify: {
              system_user_info: [this.user_info],
            },
          }),
          token: uni.getStorageSync("token"),
        };
        this.getEdit(Data);
      } else {
        this.loading = false;
        uni.showToast({
          title: "系统错误!",
          icon: "none",
        });
      }
    },

    async getEdit(data) {
      const res = await getEditAction({
        data,
      });
      uni.hideLoading();
      this.loading = false;
      if (res.redirect && res.redirect == "REDIRECT") {
        uni.navigateTo({
          url: "/pages/My/Login",
        });
      } else if (res.Status == "success") {
        uni.showToast({
          title: "认证审核中!",
          icon: "none",
          success() {
            setTimeout(() => {
              uni.navigateTo({
                url: "/pages/index/index",
              });
            }, 2000);
          },
        });
      }
    },
    back() {
      uni.navigateTo({
        url: "/pages/index/index",
      });
    },
  },
};
</script>

<style lang="scss">
.uni-file-pickerheight {
  box-sizing: border-box;
  overflow: hidden;
}

.uni-file-picker__container {
  display: flex;
  box-sizing: border-box;
  flex-wrap: wrap;
  margin: -5px;
}

.file-picker__box {
  height: 0px;
  width: 33.3%;
}

.file-picker__box {
  position: relative;
  width: 33.3%;
  height: 0;
  padding-top: 33.33%;
  box-sizing: border-box;
}

.file-picker__box-content {
  border-width: 1px;
  border-style: solid;
  border-color: rgb(238, 238, 238);
  border-radius: 3px;
}

.is-add {
  display: flex;
  align-items: center;
  justify-content: center;
}

.file-picker__box-content {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  margin: 5px;
  border: 1px #eee solid;
  border-radius: 5px;
  overflow: hidden;
}

.is-addheight {
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-addheight {
  width: 50px;
  height: 5px;
  background-color: #f1f1f1;
  border-radius: 2px;
}

.rotateheight {
  position: absolute;
  -webkit-transform: rotate(90deg);
  transform: rotate(90deg);
}

.content {
  width: 100%;
  background-color: #f5f5f5;
  // height: calc(100vh);

  .nav {
    height: 88rpx;
    background-color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-around;

    // font-weight: bold;
    view {
      height: 100%;
      display: flex;
      align-items: center;
    }

    .active {
      border-bottom: 2px solid #28a745;
    }
  }

  .cont {
    padding: 20rpx;
    box-sizing: border-box;
  }

  .item {
    width: 100%;
    height: 100%;
    background: #fff;
    border-radius: 20rpx;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 20rpx 0 0 0;
    padding: 20rpx;
    box-sizing: border-box;

    .uni-section {
      width: 100%;
    }
  }

  .foot {
    width: 100%;
    display: flex;
    justify-content: center;
  }
}
</style>